﻿using MediatR;
using SheepStorage.API.Application.Command.DepartmentCommand;
using SheepStorage.API.Application.Command.SheepManagementCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.SheepManagementHandler
{
    public class SheepManagementUpdaHandler : IRequestHandler<SheepManagementUpdaCommand, Results<int>>
    {

        private readonly ISheepManagementService sheepManagementService;

        public SheepManagementUpdaHandler(ISheepManagementService sheepManagementService)
        {
            this.sheepManagementService = sheepManagementService;
        }

        public async Task<Results<int>> Handle(SheepManagementUpdaCommand request, CancellationToken cancellationToken)
        {
            var entity = new SheepManagement
            {
                SheepManagementId = request.SheepManagementId,
                SheepYardName = request.SheepYardName,
                SheepShortName = request.SheepShortName,
                SheepScale = request.SheepScale,
                ProvinceId = request.ProvinceId,
                AreaId = request.AreaId,
                PlaceId = request.PlaceId,
                SheepAddress = request.SheepAddress,
                SheepDateTime = request.SheepDateTime,
                SheepDuty = request.SheepDuty,
                SheepIsUse = false,
                SheepManage = request.SheepManage,
            };
            var list = await sheepManagementService.UpdaSheepManagement(entity);
            return Results<int>.DataResult(list);
        }
    }
}
